USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  Table [dbo].[SPARE_PURCHASES_SALES]    Script Date: 07-Jun-14 11:54:52 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[SPARE_PURCHASES_SALES](
	[SPARE_ID] [int] IDENTITY(1,1) NOT NULL,
	[SPARE_PART_ID] [int] NOT NULL,
	[SUPPLIER_ID] [int] NOT NULL,
	[INVOICE_ID] [int] NULL,
	[SALES_INVOICE_ID] [int] NULL,
	[QUANTITY] [int] NOT NULL,
	[SPARE_UNIT_COST] [decimal](18, 2) NOT NULL,
	[SUB_TOTAL] [decimal](18, 2) NOT NULL,
	[VAT_PERCENT] [decimal](18, 2) NOT NULL,
	[TRANSACTION_TYPE] [int] NOT NULL,
	[SPARE_TYPE] [int] NOT NULL,
	[IS_WARRANTY] [bit] NULL,
	[WC_NO] [varchar](50) NULL,
 CONSTRAINT [PK_SPARE_PARCHASES] PRIMARY KEY CLUSTERED 
(
	[SPARE_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PARCHASES_SALES_MASTER] FOREIGN KEY([TRANSACTION_TYPE])
REFERENCES [dbo].[MASTER] ([MASTER_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PARCHASES_SALES_MASTER]
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PARCHASES_SALES_SPARE_PARTS] FOREIGN KEY([SPARE_PART_ID])
REFERENCES [dbo].[SPARE_PARTS] ([SPARE_PART_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PARCHASES_SALES_SPARE_PARTS]
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PURCHASES_SALES_INVOICE] FOREIGN KEY([INVOICE_ID])
REFERENCES [dbo].[INVOICE] ([INVOICE_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PURCHASES_SALES_INVOICE]
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PURCHASES_SALES_MASTER] FOREIGN KEY([SPARE_TYPE])
REFERENCES [dbo].[MASTER] ([MASTER_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PURCHASES_SALES_MASTER]
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PURCHASES_SALES_SALES_INVOICES] FOREIGN KEY([SALES_INVOICE_ID])
REFERENCES [dbo].[SALES_INVOICES] ([SALES_INVOICE_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PURCHASES_SALES_SALES_INVOICES]
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES]  WITH CHECK ADD  CONSTRAINT [FK_SPARE_PURCHASES_SALES_SUPPLIER] FOREIGN KEY([SUPPLIER_ID])
REFERENCES [dbo].[SUPPLIER] ([SUPPLIER_ID])
GO

ALTER TABLE [dbo].[SPARE_PURCHASES_SALES] CHECK CONSTRAINT [FK_SPARE_PURCHASES_SALES_SUPPLIER]
GO

